﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class morning_addStockInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            this.stime.Value = DateTime.Now.ToString("yyyy-MM-dd");
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        TemporaryModel.TemporaryEntities dal = DAL.DBManager.GetTempEmtity();

        TemporaryModel.StockBusinessInfo sbi = new TemporaryModel.StockBusinessInfo();
        try
        {
            sbi.userName = txtUserName.Text;
            sbi.wtDate = DateTime.Parse(this.stime.Value);
            sbi.stockCode = txtCode.Text;
            sbi.stockName = txtName.Text;
            sbi.wtPrice = decimal.Parse(txtPrice.Text);
            sbi.num = int.Parse(txtNum.Text);
            if (rbtnBuy.Checked)
                sbi.buyOrSell = "买入";
            else
                sbi.buyOrSell = "卖出";
            sbi.Idate = DateTime.Now;
            try
            {
                dal.AddToStockBusinessInfo(sbi);
                dal.SaveChanges();
                ClientScript.RegisterStartupScript(GetType(), "save", "alert('添加成功')", true);
                ClearTxt();
            }
            catch
            {
                ClientScript.RegisterStartupScript(GetType(), "save", "alert('添加失败')", true);
            }
        }
        catch
        {
            ClientScript.RegisterStartupScript(GetType(), "save", "alert('录入数据格式有误！请检查数据格式是否正确')", true);
         
        }
        
       // sbi.wtDate=
        //CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
        //CMSModel.Power power = new CMSModel.Power();
        //power.Id = txtId.Text;
        //power.Name = txtName.Text;
        //power.Pid = ddlPid.SelectedValue;
        //power.Url = txtUrl.Text;
        //if (rbtnForbidden.Checked)
        //    power.IsEnable = false;
        //else
        //    power.IsEnable = true;
        //try
        //{
        //    dal.AddToPower(power);
        //    dal.SaveChanges();
        //    ClientScript.RegisterStartupScript(GetType(), "save", "alert('添加成功'),document.location='Default.aspx'", true);
        //}
        //catch (Exception ex)
        //{
        //    LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.error).Write(GetType(), "addPower", LogYuMin.LogStates.ERROR, ex);
        //    ClientScript.RegisterStartupScript(GetType(), "save", "alert('添加失败')", true);
        //}
    }

    public void ClearTxt()
    {
        txtUserName.Text = "";
        txtCode.Text = "";
        txtName.Text = "";
        txtPrice.Text = "";
        txtNum.Text = "";
    }
}